﻿Public NotInheritable Class deftab
    Dim networkavailablity As Boolean
    Dim currenthost As String
    Private Sub deftab_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        adcmbo.Size = ToolStrip1.Size - My.Settings.adcmboredsize
    End Sub
    Private Sub butgo_Click(sender As Object, e As EventArgs) Handles butgo.Click
        If adcmbo.Text.Contains(".com") Or adcmbo.Text.Contains(".net") Or adcmbo.Text.Contains(".org") Then
            Try
                WebBrowser1.Source = New Uri(adcmbo.Text)
            Catch ex As System.UriFormatException
                WebBrowser1.Source = New Uri("https://" + adcmbo.Text)
                adcmbo.Text = ("https://" + adcmbo.Text)
            End Try
        Else
            WebBrowser1.Source = New Uri("https://www.google.ae/?gfe_rd=ctrl&ei=Jw04U87eMYPf8geaxoCwCg&gws_rd=cr#q=" + adcmbo.Text)
        End If
    End Sub
    Private Sub butrefresh_Click(sender As Object, e As EventArgs) Handles butrefresh.Click
        WebBrowser1.Refresh()
    End Sub
    Private Sub butstop_Click(sender As Object, e As EventArgs) Handles butstop.Click
        WebBrowser1.Stop()
        webprogress.Visible = False
    End Sub
    Private Sub butback_Click(sender As Object, e As EventArgs) Handles butback.Click
        On Error GoTo last
        WebBrowser1.GoBack()
last:
    End Sub
    Private Sub butforward_Click(sender As Object, e As EventArgs) Handles butforward.Click
        WebBrowser1.GoForward()
    End Sub
    Private Sub adcmbo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles adcmbo.KeyPress
        If e.KeyChar = Convert.ToChar(Keys.Return) Then
            If adcmbo.Text.Contains(".com") Or adcmbo.Text.Contains(".net") Or adcmbo.Text.Contains(".org") Then
                Try
                    WebBrowser1.Source = New Uri(adcmbo.Text)
                Catch ex As System.UriFormatException
                    WebBrowser1.Source = New Uri("https://" + adcmbo.Text)
                    adcmbo.Text = ("https://" + adcmbo.Text)
                End Try
            Else
                WebBrowser1.Source = New Uri("https://www.google.com/search?q=" + adcmbo.Text)
            End If
        End If
    End Sub
    Private Sub Awesomium_Windows_Forms_WebControl_DocumentReady(sender As Object, e As Awesomium.Core.DocumentReadyEventArgs) Handles WebBrowser1.DocumentReady
        On Error GoTo noicon
        If WebBrowser1.Source.Host.ToString <> currenthost Then
            Dim iconurl = "http://" + WebBrowser1.Source.Host.ToString + "/favicon.ico"
            Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(iconurl)
            Dim response As System.Net.HttpWebResponse = request.GetResponse
            Dim stream As System.IO.Stream = response.GetResponseStream
            Dim favicon = Image.FromStream(stream)
            frmMain.tabimage.Images.Add(WebBrowser1.Source.Host.ToString, favicon)
            CType(Me.Parent, TabPage).ImageKey = WebBrowser1.Source.Host.ToString
            currenthost = WebBrowser1.Source.Host.ToString
        End If
        adcmbo.Text = WebBrowser1.Source.ToString
        Me.Parent.Text = WebBrowser1.Title
        frmMain.Text = WebBrowser1.Title + " - Surfer Vio Express"
        adcmbo.URL = WebBrowser1.Source
        webprogress.Visible = False
        GoTo last
noicon:
        CType(Me.Parent, TabPage).ImageIndex = 1
last:
    End Sub
    Private Sub Awesomium_Windows_Forms_WebControl_LoadingFrame(sender As Object, e As Awesomium.Core.LoadingFrameEventArgs) Handles WebBrowser1.LoadingFrame
        webprogress.Visible = True
        With webprogress
            .Minimum = 0
            .Maximum = 50
            .Step = 5
        End With
        For index As Integer = 0 To 50 Step 5
            webprogress.Value = index
            System.Threading.Thread.Sleep(35)
        Next
    End Sub
    Private Sub Awesomium_Windows_Forms_WebControl_ShowCreatedWebView(sender As Object, e As Awesomium.Core.ShowCreatedWebViewEventArgs) Handles WebBrowser1.ShowCreatedWebView
        frmMain.addtab(newtabrequest:=True, rightclickrequest:=True)
        CType(frmMain.tabs.TabPages(frmMain.tabs.TabPages.Count - 3).Controls(0).Controls(0), Awesomium.Windows.Forms.WebControl).Source = e.TargetURL
    End Sub
    Private Sub AboutUsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutUsToolStripMenuItem.Click
        About.Show()
    End Sub
End Class
